<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>


<link rel="stylesheet" href="/crm/css/themes/base/jquery.ui.all.css">
<script src="/crm/js/jquery-1.7.2.js"></script>
<script src="/crm/js/jquery.ui.core.js"></script>
<script src="/crm/js/jquery.ui.widget.js"></script>
<script src="/crm/js/jquery.ui.button.js"></script>
<link rel="stylesheet" href="/crm/css/demos.css">

<link rel="stylesheet" href="/crm/css/icons.css">

<script src="/crm/js/icons.js"></script>

<html>
<head>
    <title>选择客户专员</title>
    <link rel="stylesheet" type="text/css" href="${base}/crm/css/public.css"/>
    <style type="text/css">
        .mytable {
            margin-top: 20px;
        }

        .mytable td {
            text-align: center;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $("#allcheck").click(function () {
                for (var i = 0; i < $(".checkboxes").length; i++) {
                    $(".checkboxes")[i].checked = true;
                }
            });
            $("#recheck").click(function () {
                for (var i = 0; i < $(".checkboxes").length; i++) {
                    $(".checkboxes")[i].checked = false;
                }
            });
            $("#change").click(function () {
                for (var i = 0; i < $(".checkboxes").length; i++) {
                    $(".checkboxes")[i].checked = !$(".checkboxes")[i].checked;
                }
            });
            $("#btnClose").click(function () {
                window.close();
            });
            $("#btnConfirm").click(function () {

                var parentInput = dialogArguments;
                //TODO...设置隐藏域 owner ids
                var ids = "";
                var names = "";
                for (var i = 0; i < $(".checkboxes").length; i++) {
                    if ($(".checkboxes")[i].checked == true) {
                        if (ids == "") {
                            ids += $(".checkboxes")[i].value;
                        } else {
                            ids += "," + $(".checkboxes")[i].value;
                        }
                        if (names == "") {
                            names += $(".checkboxes")[i].name;
                        } else {
                            names += "," + $(".checkboxes")[i].name;
                        }
                    }
                }
                parentInput.getElementById("ownerInputId").value = ids;
                //TODO...根据checkbox选项读取值
                parentInput.getElementById("ownerInput").value = names;

                window.close();
            });

        });
    </script>
</head>
<body>

<div class="pageBody">

    <form id="initOwnerList" name="initOwnerList" action="/crm/customer/initOwnerList.do" method="post">
        <button id="allcheck" type="button">全选</button>
        <button id="recheck" type="button">全不选</button>
        <button id="change" type="button">反选</button>
        <table class="mytable">

            <c:if test="${!empty users}">
                <c:forEach items="${users}" var="users">
                    <tr>
                        <td>
                            <input type="checkbox" class="checkboxes"
                                   name="${users.realName} " value="${users.id}">
                        </td>
                        <td>${users.realName}</td>
                    </tr>
                </c:forEach>
            </c:if>
        </table>
        <div class="buttonBar">
            <button id="btnConfirm">确定</button>
            <button id="btnClose">关闭</button>
        </div>
    </form>
</div>
</body>
</html>